package com.itqf.ipmsys.controller;


import com.itqf.ipmsys.dto.TrafficDto;
import com.itqf.ipmsys.dto.TrafficListDTO;
import com.itqf.ipmsys.service.TrafficService;
import com.itqf.ipmsys.utils.R;
import com.itqf.ipmsys.vo.TrafficVO;
import com.itqf.ipmsys.vo.UploadVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 交通状况表 前端控制器
 * </p>
 *
 * @author corn
 * @since 2021-09-22
 */
@CrossOrigin("*")
@RestController
@RequestMapping("/traffic")
public class TrafficController {

    @Autowired
    private TrafficService trafficService;

    @PostMapping("list")
    public R list(@RequestBody TrafficListDTO trafficListDTO) {
        List<TrafficVO> list = trafficService.findTrafficList(trafficListDTO);

        if (list == null || list.size() <= 0) {
            return R.error("暂无数据");
        }
        int total = trafficService.findTrafficCount(trafficListDTO);
        return R.ok().setData("trafficlist", list).setData("total", total);
    }

    @GetMapping("detail")
    public R detail(@RequestParam("id") Integer id) {

        TrafficVO trafficVO = trafficService.findTrafficDetail(id);
        if (trafficVO != null) {
            return R.ok("查询成功").setData("traffic", trafficVO);
        }
        return R.error("该记录不存在");
    }

    @GetMapping("delete")
    public R delete(@RequestParam("id") Integer id) {

        int result = trafficService.removeTrafficById(id);
        if (result == 1) {
            return R.ok("删除成功");
        }
        return R.error("删除失败，请重试");
    }

    @PostMapping(value = "select")
    public Object select(@RequestBody TrafficDto trafficDto) {

        List<UploadVO> data = trafficService.select(trafficDto);

        return R.ok().setData("policesituationtypes",data);
    }

}





